<?php
class CiucourseCiustudent extends AppModel {
	var $name = 'CiucourseCiustudent';
	var $validate = array(
		'ciucourse_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'ciuuser_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'score1' => array(
			'numeric' => array(
				'rule' => array('range',-0.01,5.01),
				'message' => 'Por favor ingrese un numero de 0 a 5',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				'on' => 'update', // Limit validation to 'create' or 'update' operations
			),
		),
		'score2' => array(
			'numeric' => array(
				'rule' => array('range',-0.01,5.01),
				'message' => 'Por favor ingrese un numero de 0 a 5',
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				'on' => 'update', // Limit validation to 'create' or 'update' operations
			),
		),
		'score3' => array(
			'numeric' => array(
				'rule' => array('range',-0.01,5.01),
				'message' => 'Por favor ingrese un numero de 0 a 5',
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				'on' => 'update', // Limit validation to 'create' or 'update' operations
			),
		),
                'score4' => array(
			'numeric' => array(
				'rule' => array('range',-0.01,5.01),
				'message' => 'Por favor ingrese un numero de 0 a 5',
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
                                'on' => 'update', // Limit validation to 'create' or 'update' operations
			),
		),
		'total_score' => array(
			'numeric' => array(
				'rule' => array('range',-0.01,5.01),
				'message' => 'Por favor ingrese un numero de 0 a 5',
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				'on' => 'update', // Limit validation to 'create' or 'update' operations
			),
		),
                'ciustudenttype_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
                'ciucurspersstate_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
                'transaction_number' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
         'payment_cost' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
                'ciusubject_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Ciucourse' => array(
			'className' => 'Ciucourse',
			'foreignKey' => 'ciucourse_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Ciuuser' => array(
			'className' => 'Ciuuser',
			'foreignKey' => 'ciuuser_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Ciucurspersstate' => array(
			'className' => 'Ciucurspersstate',
			'foreignKey' => 'ciucurspersstate_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Ciustudenttype' => array(
			'className' => 'Ciustudenttype',
			'foreignKey' => 'ciustudenttype_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Ciusubject' => array(
			'className' => 'Ciusubject',
			'foreignKey' => 'ciusubject_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Ciustudenttype' => array(
			'className' => 'Ciustudenttype',
			'foreignKey' => 'ciustudenttype_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
        
        function isDuplicated( $newRec ){
            $result=true;
            $sql="select count(*) as qty from ciucourse_ciustudents where "
		." payment_date='". $newRec['payment_date'] ."'"
		." and transaction_number='". $newRec['transaction_number'] ."'"
		;
	    $queryresult=$this->query($sql);
		$qty=$queryresult[0][0]['qty']; 
		if($qty<1){
			$result=false;
		}
		return $result;		
	}
        
}
